/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef THREADITEMMODEL_H
#define THREADITEMMODEL_H

#include <QObject>
#include <QAbstractListModel>
#include <QModelIndex>
#include <QPixmap>
#include "components/threadid.h"
#include "components/threadptr.h"

namespace Wishmaster
{
	class Board;
	class Thread;
	template <typename T, typename IdType>
	class EntityCollector;
}

class ThreadItemModel : public QAbstractListModel
{
	Q_OBJECT
public:
	enum eMode
	{
		mVisible = 0,
		mHidden = 1,
		mArchive = 2
	};

	ThreadItemModel(eMode mode, Wishmaster::Board* board, QObject* parent = 0);
	virtual ~ThreadItemModel();

	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	QVariant data(const QModelIndex &index, int role) const;

	void refresh();
	void update(int row);

	void setBoard(Wishmaster::Board* board);
	int getThreadRow(const Wishmaster::ThreadId& threadId);

	int page() const;
	void setPage(int p);

	static const int ThreadIdRole = Qt::UserRole + 1;
	static const int ThreadFlags = Qt::UserRole + 2;
	static const int BoardRole = Qt::UserRole + 3;
	static const int UniqueIdRole = Qt::UserRole + 4;
	static const int FullThreadIdRole = Qt::UserRole + 5;

	static const int ThreadDead = 1;
	static const int ThreadHidden = 2;
	static const int ThreadWatch = 4;
	static const int ThreadResponded = 8;

protected:
	typedef Wishmaster::EntityCollector<Wishmaster::ThreadPtr, Wishmaster::ThreadId> ThreadCollector;
	ThreadCollector* threadsByMode(eMode mode) const;

private:
	Wishmaster::Board* m_board;
	QPixmap m_deadThread;
	eMode m_mode;
	int m_page;
};

#endif

